<!--
 * @Descripttion: 
 * @version: 
 * @Author: xcb
 * @Date: 2021-03-16 09:48:46
 * @LastEditors: gzy 810461372@qq.com
 * @LastEditTime: 2023-08-29 14:57:17
-->
<template>
  <BoundaryCondition v-if="planDataMsgForm.planno" />
</template>

<script lang="ts">
import {
  ref,
  defineComponent,
  reactive,
  toRefs,
  onMounted,
  provide,
} from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
import { ElMessage, ElMessageBox, FormInstance, FormRules } from "element-plus";
import BoundaryCondition from "./boundaryCondition/index.vue";

import moment, { Moment } from "moment";

import { selectSingleWaterModelInfo } from "@/request/api";

export default defineComponent({
  name: "modelFormulasAdd",
  components: {
    BoundaryCondition,
  },
  setup: () => {
    const router = useRouter(),
      route = useRoute(),
      store = useStore();

    const state = reactive({});

    // 边界条件数据
    const boundaryConditionData = reactive({});

    // 边界条件站点树状图数据
    const boundaryConditionTreeData = reactive({
      // 站点树状图所选站点
      treeSelect: {
        key: "",
        type: "",
        stcd: "",
      },
      // 站点树状图所选站点stcd
      treeSelectStcd: [],
      // 站点树状图数据
      treeData: [],
    });

    // 方案参数信息
    let planDataMsgForm = reactive({
      // 方案id
      planno: route.params.id,
      // 方案数据
      planData: [],
      // 方案所选库区
      selectReservoir: route.params.reservoir,
      // 参数方案选择
      selectParamPlan: "",
      // 方案时间
      dateTime: [
        moment().subtract(7, "days").format("YYYY-MM-DD 00:00:00"),
        moment().add(3, "days").format("YYYY-MM-DD 23:59:59"),
      ],
      // 预测天数
      predictDay: 3,
      // 当前方案为新增还是修改
      isEdit: false,
      // 当前方案是否为该用户创建
      verifyUser: true,
    });

    // 方案参数信息
    provide("planDataMsgForm", planDataMsgForm);

    // 边界条件数据
    provide("boundaryConditionData", boundaryConditionData);

    // 边界条件树状图数据
    provide("boundaryConditionTreeData", boundaryConditionTreeData);

    onMounted(() => {
      getPlanData();
    });

    async function getPlanData() {
      const requestData: any = await selectSingleWaterModelInfo({
        id: planDataMsgForm.planno,
      });

      planDataMsgForm.planData = requestData[0].list.map((item) => {
        item.remark = item.remark.split(",");

        return item;
      });
    }

    return {
      ...toRefs(state),

      planDataMsgForm,
    };
  },
});
</script>

<style scoped lang="less">
.addBox {
  display: inline-block;
  position: relative;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
</style>
